# -*- coding: utf-8 -*-
# create a JSON-RPC-server
import utils.jsonrpc as jsonrpc
#server = jsonrpc.Server(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 31415), logfunc=jsonrpc.log_file("myrpc.log")))

server = jsonrpc.Server(jsonrpc.JsonRpc20(), jsonrpc.TransportUnixSocket(addr="/home/alicante/Desktop/socketipc", logfunc=jsonrpc.log_file("myrpc.log")))


# define some example-procedures and register them (so they can be called via RPC)
def echo(s):
    return s

def ditbonjour():
    return "bonjour"


def search(number=None, last_name=None, first_name=None):
    sql_where = []
    sql_vars  = []
    if number is not None:
        sql_where.append("number=%s")
        sql_vars.append(number)
    if last_name is not None:
        sql_where.append("last_name=%s")
        sql_vars.append(last_name)
    if first_name is not None:
        sql_where.append("first_name=%s")
        sql_vars.append(first_name)
    sql_query = "SELECT id, last_name, first_name, number FROM mytable"
    if sql_where:
        sql_query += " WHERE" + " AND ".join(sql_where)

    return "ta mere est une pute"


server.register_function( ditbonjour )
server.register_function( echo )
server.register_function( search )

# start server
server.serve()